package
{
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;

	public class graficTrigonometrie extends MovieClip
	{
		var Grafic : grafic = new grafic();
		var Cerc : cerc = new cerc();
		var Panta : panta = new panta(Grafic);
		var m : Number = 1;
		
		var sin,cos,tg,ctg : myText;
		
		public function graficTrigonometrie()
		{
			this.addEventListener(Event.ADDED_TO_STAGE,initializare);
		}
		
		private function initializare(e:Event):void
		{
			this.addChild(Grafic);
			this.addChild(Cerc);
			this.addChild(Panta);
			
			var alfa : Number;
			
			alfa = Math.atan(m);
			
			sin.text = "sin(x) = "+Math.sin(alfa).toFixed(CONST.prec);
			cos.text = "cos(x) = "+Math.cos(alfa).toFixed(CONST.prec);
			tg.text = "tg(x) = "+Math.tan(alfa).toFixed(CONST.prec);
			ctg.text = "ctg(x) = "+(1/Math.tan(alfa)).toFixed(CONST.prec);
			
			Grafic.addEventListener(Event.ADDED_TO_STAGE,init2);
		}
		
		private function init2(e:Event):void
		{
			Grafic.setUnitate = 130;
			traseazaCerc();
			
			this.mouseChildren = false;
			
			this.addEventListener(MouseEvent.MOUSE_DOWN,trage);
		}
		
		private function trage(e:MouseEvent):void
		{
			this.addEventListener(MouseEvent.MOUSE_UP,lasa);
			this.addEventListener(MouseEvent.MOUSE_MOVE,muta);
			this.addEventListener(MouseEvent.MOUSE_OUT,lasa);
		}
		
		private function lasa(e:MouseEvent):void
		{
			this.removeEventListener(MouseEvent.MOUSE_UP,lasa);
			this.removeEventListener(MouseEvent.MOUSE_MOVE,muta);
			this.removeEventListener(MouseEvent.MOUSE_OUT,lasa);
		}
		
		private function muta(e:MouseEvent):void
		{
			m=(Grafic.oY-e.localY)/(e.localX-Grafic.oX);
			
			var alfa : Number;
			var s,c,t,ct : String;
			
			alfa = Math.atan(m);
			
			if(e.localX>Grafic.oX)
				s = Math.sin(alfa).toFixed(CONST.prec);
			else
				s = (-Math.sin(alfa)).toFixed(CONST.prec);
			
			if(e.localX>Grafic.oX)
				c = Math.cos(alfa).toFixed(CONST.prec);
			else
				c = (-Math.cos(alfa)).toFixed(CONST.prec);
			
			t = Math.tan(alfa).toFixed(CONST.prec);
			ct = (1/Math.tan(alfa)).toFixed(CONST.prec);
			
			sin.text = "sin(x) = "+s;
			cos.text = "cos(x) = "+c;
			tg.text = "tg(x) = "+t;
			ctg.text = "ctg(x) = "+ct
			
			if(e.localX<Grafic.oX)
				Panta.deseneaza(m,2);
			else
				Panta.deseneaza(m,1);
		}
		
		public function traseazaCerc():void
		{
			Cerc.traseazaCerc(Grafic);
		}
		
		public function transmite(a:myText,b:myText,c:myText,d:myText)
		{
			sin = a;
			cos = b;
			tg = c;
			ctg = d;
		}
	}
}